package vn.co.thn.android.store;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.toolbox.ImageLoader.ImageCache;

public class NSImageLruCache implements ImageCache {
	private LruCache<String, Bitmap> mMemoryCache;

	public NSImageLruCache() {
		// final int maxMemory = (int) (Runtime.getRuntime().maxMemory() /
		// 1024);
		// final int cacheSize = maxMemory / 8;
		// TODO 容量計算について要検討
		final int cacheSize = 50 * 1024 * 1024;

		mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
			@Override
			protected int sizeOf(String key, Bitmap bitmap) {
				// return bitmap.getByteCount();
				return bitmap.getRowBytes() * bitmap.getHeight();
			}
		};
	}

	@Override
	public Bitmap getBitmap(String url) {
		return mMemoryCache.get(url);
	}

	@Override
	public void putBitmap(String url, Bitmap bitmap) {
		mMemoryCache.put(url, bitmap);
	}

}
